import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';

import 'package:logging/logging.dart';

import 'screens/home/home_screen.dart' as _homeTab;
import 'screens/order/order_screen.dart' as _orderTab;
import 'screens/mine/mine_screen.dart' as _mineTab;

import 'routes.dart';
import './config/application.dart';

final _logger = new Logger('main tabbar');

class MainTabbar extends StatefulWidget {
  @override
  _MainTabbarState createState() => _MainTabbarState();
}

class _MainTabbarState extends State<MainTabbar> {
 
  _MainTabbarState() {
    
  }


  PageController _tabController;
  var _title_app = null;
  var _tab = 0;
  
  @override
  void initState() {
    super.initState();
    this._tabController = new PageController();
    this._title_app = tabItems[0].title;
  }

  @override
  void dispose() {
    super.dispose();
    this._tabController.dispose();

  }
 

  @override
  Widget build(BuildContext context) {
    
    return Scaffold(
      
      // appBar: AppBar(
      //   title: Text(
      //     _title_app,
      //     style: new TextStyle(
      //       fontSize: Theme.of(context).platform == TargetPlatform.iOS ? 17.0 : 20.0,
      //     ),
      //   ),
      //   elevation: Theme.of(context).platform == TargetPlatform.iOS ? 0.0 : 40.0,
      // ),

      body: new PageView(
        controller: _tabController,
        onPageChanged: onTabChanged,
        children: <Widget>[
          new _homeTab.HomeScreen(),
          new _orderTab.OrderScreen(),
          new _mineTab.MineScreen(),
        ],
      ),
      bottomNavigationBar:
        new BottomNavigationBar(
            currentIndex: _tab,
            onTap: onTap,
            items: tabItems.map((TabItem) {
              return new BottomNavigationBarItem(
                title: new Text(TabItem.title),
                icon: new Icon(TabItem.icon),

              );
            }).toList()
        ),
      

    );
  }

  void onTap(int tab) {
    _tabController.jumpToPage(tab);
  }

  void onTabChanged(int tab) {
    setState(() {
        this._tab = tab;
    });

    _logger.finest(" ------ ======== --- $tab ");

    this._title_app = tabItems[tab].title;
    switch (tab) {
      case 0:
        
        break;
      case 1:

        break;
      case 2:

        break;
    }

  }

}


class TabItem {
  const TabItem({ this.title, this.icon });
  final String title;
  final IconData icon;
}


const List<TabItem> tabItems = const <TabItem>[
  
  const TabItem(title: '首页', icon: Icons.home),
  const TabItem(title: '订单', icon: Icons.list),
  const TabItem(title: '我的', icon: Icons.settings),

];
 
